{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 文件操作\n",
    "from operator import *\n",
    "# url解码用的\n",
    "import urllib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 正常样本\n",
    "fn = open('src/replace1.txt')\n",
    "# 攻击payload\n",
    "fp = open('src/payload.txt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 将样本放入列表的函数，如果列表中有了，就不重复放进去\n",
    "def putInList(word,list):\n",
    "    if word in list:\n",
    "        return -1\n",
    "    else:\n",
    "#         print word\n",
    "        list.append(word)\n",
    "        return 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 正常请求列表\n",
    "listNormal = []\n",
    "# 攻击payload 列表\n",
    "listPayload = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 对正常请求去重\n",
    "for line in fn.readlines():\n",
    "    putInList(line,listNormal)\n",
    "# 对攻击流量去重\n",
    "for line in fp.readlines():\n",
    "    putInList(line,listPayload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正常参数数量\n",
      "643\n",
      "payload 数量\n",
      "4571\n"
     ]
    }
   ],
   "source": [
    "# 显示结果\n",
    "print \"正常参数数量\"\n",
    "print len(listNormal)\n",
    "print \"payload 数量\"\n",
    "print len(listPayload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 结果写入文件"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
